import Vue from 'vue'
import VueRouter from 'vue-router'
import index from '../views/index.vue'
// import forgetPassword from '../views/forgetPassword.vue'
import cookie from 'js-cookie'

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        redirect: '/index'
    },

    {
        path: '/index',
        name: '/index',
        component: index,

    },
    {
        path: '/forgetPassword',
        name: 'forgetPassword',
        component: () => import(/* webpackChunkName: "index" */ '../views/forgetPassword.vue')
    },
    {
        path: '/login',
        name: 'login',
        component: () => import(/* webpackChunkName: "index" */ '../views/login.vue')
    },
    {
        path: '/my',
        name: 'my',
        component: () => import(/* webpackChunkName: "index" */ '../views/my.vue')
    },

    {
        path: '/task',
        name: 'task',
        component: () => import(/* webpackChunkName: "index" */ '../views/task/index.vue')
    },
    {
        path: '/publishTask',
        name: 'publishTask',
        component: () => import(/* webpackChunkName: "index" */ '../views/publishTask/index.vue')
    },
    {
        path: '/businessManage',
        name: 'businessManage',
        component: () => import(/* webpackChunkName: "index" */ '../views/businessManage/index.vue')
    },
    {
        path: '/createBusiness',
        name: 'createBusiness',
        component: () => import(/* webpackChunkName: "index" */ '../views/businessManage/createBusiness.vue')
    },
    {
        path: '/businessQuery',
        name: 'businessQuery',
        component: () => import(/* webpackChunkName: "index" */ '../views/businessQuery/index.vue')
    },
    {
        path: '/identityQuery',
        name: 'identityQuery',
        component: () => import(/* webpackChunkName: "index" */ '../views/identityQuery/index.vue')
    },

     {
        path: '/recommend',
        name: 'recommend',
        component: () => import(/* webpackChunkName: "index" */ '../views/recommend/index.vue')
    },

  {
        path: '/recommendRegister',
        name: 'recommendRegister',
        component: () => import(/* webpackChunkName: "index" */ '../views/recommendRegister/index.vue')
    },
  {
        path: '/jingpaidanAudit',
        name: 'jingpaidanAudit',
        component: () => import(/* webpackChunkName: "index" */ '../views/jingpaidanAudit/index.vue')
    },
{
        path: '/settings',
        name: 'settings',
        component: () => import(/* webpackChunkName: "index" */ '../views/settings/index.vue')
    },
{
        path: '/realnameAuthentication',
        name: 'realnameAuthentication',
        component: () => import(/* webpackChunkName: "index" */ '../views/realnameAuthentication/index.vue')
    },
{
        path: '/customer',
        name: 'customer',
        component: () => import(/* webpackChunkName: "index" */ '../views/customer/index.vue')
    },
    {
        path: '/helpDetail',
        name: 'helpDetail',
        component: () => import(/* webpackChunkName: "index" */ '../views/customer/helpDetail.vue')
    },
    {
        path: '/myWorkDetail',
        name: 'myWorkDetail',
        component: () => import(/* webpackChunkName: "index" */ '../views/customer/myWorkDetail.vue')
    },
{
        path: '/ordinaryTable',
        name: 'ordinaryTable',
        component: () => import(/* webpackChunkName: "index" */ '../views/ordinaryTable/index.vue')
    },


{
        path: '/quit',
        name: 'quit',
        component: () => import(/* webpackChunkName: "index" */ '../views/quit/index.vue')
    },

    {
        path: '/assignment',
        name: 'assignment',
        component: () => import(/* webpackChunkName: "index" */ '../views/assignment.vue')
    },
    {
        path: '/myAssignment',
        name: 'myAssignment',
        component: () => import(/* webpackChunkName: "index" */ '../views/myAssignment.vue')
    },
    {
        path: '/livingCircle',
        name: 'livingCircle',
        component: () => import(/* webpackChunkName: "index" */ '../views/livingCircle.vue')
    },
    {
        path: '/publishCon',
        name: 'publishCon',
        component: () => import(/* webpackChunkName: "index" */ '../views/publishCon.vue')
    },
    {
        path: '/assignmentDetail',
        name: 'assignmentDetail',
        component: () => import(/* webpackChunkName: "index" */ '../views/assignmentDetail.vue')
    },
    {
        path: '/tabbar',
        name: 'tabbar',
        component: () => import(/* webpackChunkName: "index" */ '../components/base/tabbar.vue')
    },
    {
        path: '/headTop',
        name: 'headTop',
        component: () => import(/* webpackChunkName: "index" */ '../components/base/headTop.vue')
    },

]

const router = new VueRouter({
    routes
})
// 全局路由守卫
router.beforeEach((to, from, next) => {
    let login = cookie.get("Authorization")
    // 登陆界面
    if (to.path == "/login"  // 登录
        || to.path == "/forgetPassword"  // 忘记密码
        || to.path=="/identityQuery" // 身份查询
    ) {
        next();
        return;
    } else {
        // 判断是否登陆
        if (!login) {
            next('/login');
            return;
        } else {
            next();
        }
    }
})
export default router
